extends Camera2D

var motion := Vector2()

export (float) var zoom_min = 1.5
export (float) var zoom_max = 6
var current_zoom = 4

func _ready():
	zoom_by(current_zoom)

func zoom_by(v: float):
	var z = 1/v
	zoom = Vector2(z, z)

func _process(delta):
	if Input.is_mouse_button_pressed(BUTTON_MIDDLE):
		position -= motion
	motion = Vector2()

func _input(event):
	if event is InputEventMouseMotion:
		motion = event.relative * zoom
	if event is InputEventMouseButton:
		if event.is_pressed():
			if event.button_index == BUTTON_WHEEL_DOWN:
				current_zoom = lerp(current_zoom, zoom_min, 0.2)
				zoom_by(current_zoom)
			if event.button_index == BUTTON_WHEEL_UP:
				current_zoom = lerp(current_zoom, zoom_max, 0.2)
				zoom_by(current_zoom)
